<?php
/*
 * 主页，用户基本信息，头像，任务，部门公告，公司公告，公司新闻
 * 
 * @author Lee <a605333742@gmail.com>
 * @time 2016-04-19  
 */
namespace Home\Controller;

class IndexController extends AllowController{
    /*
     * 构造函数
     *
     * @return  #
     */
    public function _initialize(){ 
        parent::_initialize();
        $this->club     =D("Club");
        $this->clubGroup=D('ClubGroup');
        $this->user     =D('User');
        $this->top      =D("Top");
        $this->visit    =D("Visit");
        $this->web      =D("Web");
        
    }
    /*
     * 主页，展示详细信息
     * 
     * @return #
     */
    public function index() {
        C("PAGE_JUMP_PARAM",1);
        A("Allow")->firstInfo();
        $ord['top']     =desc;
        //最近两条公告列表
        $where=array(
            "status"    =>1,            
            "section_id"=>1,
            "sign"      =>1
        );
        $noTwoList      =$this->db_notice->where($where)->order($ord)->limit(1,2)->Field("id,title,en_title,user_id,content,en_content")->select();
        
        /*最新两条活动 start*/
        $where1['status']   =1;
        $ord1['add_time']   =desc;
        $clubList           =$this->club->where($where1)->order($ord1)->limit(0,2)->select(); 
        foreach($clubList as $k=>$v){
            //获取关联的俱乐部
            $clubList[$k]["groupInfo"]  =$this->clubGroup->find($clubList[$k]['group_id']);           
            $clubList[$k]['name']       =$clubList[$k]["groupInfo"]['name'];
            $clubList[$k]['logo']       =$clubList[$k]["groupInfo"]['logo'];
            //获取关联的用户
            $clubList[$k]["userInfo"]   =$this->user->field("name,image")->find($clubList[$k]['assign_user_id']);
            $clubList[$k]['userName']   =$clubList[$k]["userInfo"]['name'];
            $clubList[$k]['en_name']    =$clubList[$k]["userInfo"]['nickname'];
            $clubList[$k]['small_photo']=$clubList[$k]["userInfo"]['image'];
            unset($clubList[$k]["groupInfo"]);
            unset($clubList[$k]["userInfo"]);
        }
        /*最新两条活动end*/ 
        /*访问统计  start*/
        $ip         =$_SERVER['REMOTE_ADDR'];
        $today      =strtotime(date('y-m-d'));
        $map['ip']  =$ip;
        $visit  =$this->visit->where($map)->find();
        if($visit){
            if(((integer)$visit['last_time'])<$today){
                //如果上次访问时间小于今天凌晨0点，则说明上次访问是在昨天，今天访问可以+1
                $this->web->where(array("id"=>1))->setInc("statistics_");
                $map['id']          =$visit['id'];
                $map['last_time']   =time();
                $this->visit->save($map);
            }
        }else{
            $map['last_time']   =time();
            $this->web->where(array("id"=>1))->setInc("statistics_");
            $this->visit->add($map);
        }
        /*访问统计  end*/
        
        $wheres['status']   =1;
        $photoList          =$this->top->where($wheres)->order("sort_".' '.asc)->select();
        $this->assign("pList",$photoList);
        $this->assign("noTwoList",$noTwoList);  //最近两条公告列表列表
        $this->assign("clubList",$clubList);    //最新两条活动列表
        
        $this->display("index");
    }
}
